package com.shierke.Ume.ui.activity

import MainAdapter
import android.content.Context
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.next.easynavigation.view.EasyNavigationBar
import com.shierke.Ume.R
import com.shierke.Ume.ui.fragment.explore.ExploreFragment
import com.shierke.Ume.ui.fragment.match.MatchFragment
import com.shierke.Ume.ui.fragment.me.MeFragment
import com.shierke.Ume.ui.fragment.message.MessageFragment
import com.shierke.Ume.util.click
import com.shierke.Ume.util.startActivity
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {


    companion object {

        fun startActivity(context: Context) {
            context.startActivity<MainActivity>()
        }

    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        //StatusBarUtils.setStatusBarTransparentAndFullScreen(this)

        initViewPager()
        initBottomNavigation()
    }


    private fun initViewPager() {
//        adapter = MainAdapter(supportFragmentManager)
//        viewPager.offscreenPageLimit = adapter.count
//        viewPager.adapter = adapter

        val fragments: ArrayList<Fragment> = arrayListOf()

        fragments.add(MatchFragment())
        fragments.add(ExploreFragment())
        fragments.add(MessageFragment())
        fragments.add(MeFragment())

        val title = arrayOf<String>(
            getString(R.string.home_tab_match)
            , getString(R.string.home_tab_explore)
            // , getString(R.string.home_tab_add)
            , getString(R.string.home_tab_message)
            , getString(R.string.home_tab_me)
        )


        var selectImage = intArrayOf(
            R.mipmap.home_match_sel,
            R.mipmap.home_explore_sel,
            //  R.mipmap.home_add_sel,
            R.mipmap.home_message_sel,
            R.mipmap.home_me_sel
        )


        var noSelectIamge = intArrayOf(
            R.mipmap.home_match_no,
            R.mipmap.home_explore_no,
            //R.mipmap.home_add_sel,
            R.mipmap.home_message_no,
            R.mipmap.home_me_no
        )



        bottomNavigation.defaultSetting()
            .titleItems(title)
            .fragmentList(fragments)       //  fragment集合
            .fragmentManager(supportFragmentManager)
            .canScroll(false)
            .hasPadding(false)
            .selectIconItems(selectImage)
            .normalIconItems(noSelectIamge)
            .navigationHeight(50)
            .tabTextSize(10)
            .normalTextColor(Color.parseColor("#9C9C9C"))   //Tab未选中时字体颜色
            .selectTextColor(Color.parseColor("#D600E9"))   //Tab选中时字体颜色
            .navigationBackground(Color.parseColor("#00000000"))
            .lineHeight(0)
            .centerImageRes(R.mipmap.home_add_sel)  //中间按钮
            .centerIconSize(1f)    //中间加号图片的大小
            //.centerLayoutHeight(120)
            .centerAlignBottom(true)
            .mode(EasyNavigationBar.NavigationMode.MODE_ADD)
            //.centerLayoutBottomMargin(-50)
            .centerLayoutRule(EasyNavigationBar.RULE_CENTER)
            //.centerTextTopMargin(-20)  //加号文字距离加号图片的距离
            .centerTextSize(0)      //加号文字大小
            .build()


        addExplore.click { AddTrendsActivity.startActivity(this) }


    }


    private lateinit var adapter: MainAdapter

    fun mainFragments() = adapter.fragments


    private fun initBottomNavigation() {


//        bottomNavigation.addItems(
//            mutableListOf(
//                AHBottomNavigationItem(
//                    getString(R.string.home_tab_match),
        // R.drawable.select_home_match
//                ),
//                AHBottomNavigationItem(
//                    getString(R.string.home_tab_explore),
//                    R.drawable.select_home_explore
//                ),
//
//                AHBottomNavigationItem(
//                    getString(R.string.home_tab_add),
//                    R.drawable.select_home_add
//                ),
//
//                AHBottomNavigationItem(
//                    getString(R.string.home_tab_message),
//                    R.drawable.select_home_message
//                ),
//                AHBottomNavigationItem(
//                    getString(R.string.home_tab_me),
//                    R.drawable.select_home_me
//                )
//            )
//        )


//        bottomNavigation.inactiveColor = Color.parseColor("#666666")
//
//        bottomNavigation.isTranslucentNavigationEnabled = true
//
//        bottomNavigation.defaultBackgroundColor = Color.TRANSPARENT
//
//        // bottomNavigation.accentColor = getColorByRes(R.color.colorPrimary)
//        bottomNavigation.titleState = AHBottomNavigation.TitleState.ALWAYS_SHOW
//
//        bottomNavigation.setNotificationAnimationDuration(0)
//        bottomNavigation.setTitleTextSizeInSp(12F, 12F)
//
//        bottomNavigation.setOnTabSelectedListener { position, wasSelected ->
//
//            if (position < 2) {
//                viewPager.setCurrentItem(position, false)
//            } else if (position == 2) {
//                AddTrendsActivity.startActivity(this)
//            } else if (position > 2) {
//                viewPager.setCurrentItem(position - 1, false)
//            }
//
//            return@setOnTabSelectedListener true
//        }
    }


}


